import { api } from "@/api/index";
import * as TYPE from "../action-type";

const app = {
  setCollapsed(flag) {
    return {
      type: TYPE.SETCOLLAPSED,
      collapsed: flag,
    };
  },
  setLoginFlag(flag) {
    return {
      type: TYPE.SETLOGINFLAG,
      loginFlag: flag,
    };
  },
  setRegisterFlag(flag) {
    return {
      type: TYPE.SETREGISTERFLAG,
      registerFlag: flag,
    };
  },
  setForgetFlag(flag) {
    return {
      type: TYPE.SETFORGETFLAG,
      forgetFlag: flag,
    };
  },
  setSearchFlag(flag) {
    return {
      type: TYPE.SETSEARCHFLAG,
      searchFlag: flag,
    };
  },
  getBlogInfo() {
    return new Promise(async (resolve, reject) => {
      try {
        let res = await api.getHomeData();
        if (res.code === 0) {
          resolve({
            type: TYPE.APP_GETBLOGINFO,
            blogInfo: res.data,
          });
        } else {
          reject({
            type: "ERROR",
          });
        }
      } catch (error) {
        reject({
          type: "ERROR",
        });
      }
    });
  },
};

export default app;
